package com.future.mayi.qsale.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;


import com.future.mayi.R;
import com.future.mayi.dialog.ShareDialog;
import com.future.mayi.qsale.model.RedPacketInfoModel;
import com.future.mayi.utils.HCUtils;

/**
 * Created by Administrator on 2018/8/23.
 */

public class PrizeDrawResultDialog extends Dialog {

    private Context mContext;
    private RedPacketInfoModel.PrizeInfoBean mResultPrizeInfo;

    public PrizeDrawResultDialog(@NonNull Context context, RedPacketInfoModel.PrizeInfoBean prizeInfoBean) {
        super(context, R.style.dialog);
        setContentView(R.layout.dialog_prize_draw);
        setCancelable(false);
        this.mContext = context;
        this.mResultPrizeInfo = prizeInfoBean;
    }

    private ImageView ivResultImg;
    private TextView tvCancel;
    private TextView tvConfirm;
    private ShareDialog mShareDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initDialogWidth();
        ivResultImg = (ImageView) findViewById(R.id.iv_result_img);
        tvCancel = (TextView) findViewById(R.id.tv_cancel);
        tvConfirm = (TextView) findViewById(R.id.tv_confirm);

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PrizeDrawResultDialog.this.dismiss();
            }
        });
        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PrizeDrawResultDialog.this.dismiss();
                if (mShareDialog == null) {
                    mShareDialog = new ShareDialog((Activity) mContext);
                }
                mShareDialog.show("我在跑跑体育中奖啦", mResultPrizeInfo.getPrize_name(), mResultPrizeInfo.getPrize_img(), "http://shewuwang.com/");
            }
        });
        HCUtils.loadWebImg(mContext, ivResultImg, mResultPrizeInfo.getPrize_img());
    }

    private void initDialogWidth() {
        Window window = getWindow();
        if (window == null) {
            return;
        }
        window.setDimAmount(0.8f); // 部分刷机会导致背景透明，这里保证一次
        WindowManager.LayoutParams wmlp = window.getAttributes();
        wmlp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        window.setAttributes(wmlp);
    }


}
